Keyword-Driven Framework in Selenium
A Keyword-Driven Framework is a Selenium automation framework in which test cases are designed using predefined keywords that represent specific actions. Instead of writing Selenium commands directly in every test case, testers use reusable keywords such as OpenBrowser, OpenURL, EnterText, Click, VerifyText, SelectDropdown, TakeScreenshot, and CloseBrowser.
Each keyword is mapped to an automation method that performs the actual Selenium operation. This creates a separation between test steps and automation implementation. Keyword-driven frameworks are commonly used as part of larger Selenium automation architectures and can be combined with Page Object Model, data-driven testing, TestNG, Maven, reporting, logging, and CI/CD practices.
JustAcademy's Selenium curriculum includes keyword-driven framework development along with Page Object Model, data-driven frameworks, hybrid framework design, reusable test architecture, TestNG, reporting, logging, debugging, Selenium Grid and CI/CD concepts. :contentReference[oaicite:0]{index=0}
Course Resource: Selenium Training | Register for Course Demo
1. What Is a Keyword-Driven Framework?
A Keyword-Driven Framework is an automation framework where the actions required to execute a test are represented by predefined keywords. The framework reads these keywords and executes the corresponding Selenium methods.
For example, a login test can be represented as:
OpenBrowser
OpenURL
EnterText
EnterText
Click
VerifyText
CloseBrowser
Each keyword represents a reusable operation. The actual Selenium implementation remains inside the framework rather than being repeated in every test case.
2. Simple Example of Keyword-Driven Testing
Suppose we want to automate a login page.
In a normal Selenium script, we might write:
driver.get("https://example.com/login");
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("Admin123");
driver.findElement(By.id("login")).click();
In a keyword-driven framework, the same test can be represented as:
| Step | Keyword | Object | Value |
| 1 | OpenBrowser | - | Chrome |
| 2 | OpenURL | - | https://example.com/login |
| 3 | EnterText | username | admin |
| 4 | EnterText | password | Admin123 |
| 5 | Click | login | - |
| 6 | VerifyText | message | Welcome |
| 7 | CloseBrowser | - | - |
The test case describes the required actions while the keyword library contains the Selenium implementation.
3. Why Do We Need a Keyword-Driven Framework?
When a Selenium project grows, many test cases repeatedly perform similar operations. For example, hundreds of tests may need to open a browser, enter text, click buttons, select dropdown values, verify messages, and close the browser.
Writing the same Selenium code repeatedly increases duplication and maintenance effort. A keyword-driven framework provides reusable actions that can be called from many test cases.
- Reduces duplicate Selenium code.
- Provides reusable automation actions.
- Separates test design from implementation.
- Makes test cases easier to understand.
- Centralizes common Selenium operations.
- Improves maintainability.
- Supports large automation suites.
- Can be integrated with external test data.
- Can be combined with POM.
- Supports framework-level reporting and logging.
4. Main Principle of Keyword-Driven Framework
The main principle is to convert commonly performed automation operations into reusable keywords.
Test Case
|
v
Keyword
|
v
Keyword Engine
|
v
Keyword Implementation
|
v
Selenium WebDriver
|
v
Web Application
For example:
Keyword Selenium Operation
-----------------------------------------
OpenBrowser Create WebDriver
OpenURL driver.get()
EnterText sendKeys()
Click click()
GetText getText()
VerifyText Assertion
Screenshot TakesScreenshot
CloseBrowser driver.quit()
5. Keyword-Driven Framework vs Normal Selenium Script
| Normal Selenium Script | Keyword-Driven Framework |
| Selenium code is directly written in test methods. | Test actions are represented through keywords. |
| Code may be duplicated across tests. | Common actions are reusable. |
| Test and implementation are often closely coupled. | Test steps can be separated from implementation. |
| Maintenance may become difficult as the suite grows. | Centralized keyword implementations can simplify maintenance. |
| Usually easier to start. | Requires framework design and keyword engine development. |
6. Components of a Keyword-Driven Framework
A complete keyword-driven Selenium framework generally contains the following components:
| Component | Purpose |
| Test Cases | Defines the required test steps. |
| Keyword Repository | Stores available keywords. |
| Keyword Engine | Reads keywords and executes them. |
| Keyword Library | Contains reusable Selenium methods. |
| Object Repository | Stores application element information. |
| Test Data | Provides input values. |
| Configuration | Stores browser, URL and environment settings. |
| Utilities | Provides reusable helper functions. |
| Assertions | Validates expected results. |
| Reporting | Generates execution reports. |
| Logging | Records framework execution information. |
7. Keyword Repository
A Keyword Repository is a collection of predefined keywords supported by the automation framework.
OpenBrowser
CloseBrowser
OpenURL
RefreshPage
NavigateBack
EnterText
ClearText
Click
DoubleClick
MouseHover
SelectDropdown
WaitForElement
VerifyText
VerifyTitle
VerifyURL
TakeScreenshot
SwitchFrame
SwitchWindow
AcceptAlert
DismissAlert
Each keyword should have a clear purpose and a corresponding implementation.
8. Keyword Library
The Keyword Library contains the Java methods responsible for performing the actual Selenium operations.
public class KeywordLibrary {
public void click(WebDriver driver, By locator) {
driver.findElement(locator).click();
}
public void enterText(WebDriver driver,
By locator,
String value) {
driver.findElement(locator).sendKeys(value);
}
public void clearText(WebDriver driver,
By locator) {
driver.findElement(locator).clear();
}
public String getText(WebDriver driver,
By locator) {
return driver.findElement(locator).getText();
}
}
The same methods can be reused by many test cases.
9. Keyword Engine
The Keyword Engine is responsible for reading the test steps and deciding which keyword implementation should be executed.
Read Test Case
|
v
Read Keyword
|
v
Validate Keyword
|
v
Read Object
|
v
Read Value
|
v
Find Keyword Method
|
v
Execute Selenium Action
|
v
Capture Result
|
v
Read Next Step
10. Keyword Mapping
The framework maps each keyword to a corresponding Java method.
| Keyword | Java Method | Purpose |
| OpenBrowser | openBrowser() | Launch browser. |
| OpenURL | openUrl() | Navigate to URL. |
| EnterText | enterText() | Enter text. |
| Click | click() | Click an element. |
| ClearText | clearText() | Clear input. |
| VerifyText | verifyText() | Verify displayed text. |
| VerifyTitle | verifyTitle() | Verify page title. |
| Screenshot | takeScreenshot() | Capture screenshot. |
| CloseBrowser | closeBrowser() | Close browser. |
11. Basic Keyword Class in Selenium
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class KeywordActions {
private WebDriver driver;
public void openBrowser() {
driver = new ChromeDriver();
driver.manage().window().maximize();
}
public void openUrl(String url) {
driver.get(url);
}
public void enterText(String locator, String value) {
driver.findElement(By.id(locator)).sendKeys(value);
}
public void click(String locator) {
driver.findElement(By.id(locator)).click();
}
public void closeBrowser() {
if (driver != null) {
driver.quit();
}
}
}
12. Creating a Login Keyword Library
For a login application, generic keywords can be used instead of creating separate Selenium code for every login test.
OpenBrowser
OpenURL
EnterText
EnterText
Click
VerifyText
CloseBrowser
Values can be provided separately:
OpenBrowser | Chrome
OpenURL | https://example.com/login
EnterText | username | admin
EnterText | password | Admin123
Click | login
VerifyText | message | Welcome
CloseBrowser
13. Complete Keyword-Driven Login Example
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginKeywords {
private WebDriver driver;
public void openBrowser() {
driver = new ChromeDriver();
driver.manage().window().maximize();
}
public void openUrl(String url) {
driver.get(url);
}
public void enterText(String locator, String value) {
driver.findElement(By.id(locator)).sendKeys(value);
}
public void click(String locator) {
driver.findElement(By.id(locator)).click();
}
public boolean verifyText(String locator,
String expected) {
String actual =
driver.findElement(By.id(locator)).getText();
return actual.equals(expected);
}
public void closeBrowser() {
if (driver != null) {
driver.quit();
}
}
}
14. Keyword-Driven Framework with TestNG
TestNG can be used as the test execution framework while the keyword layer handles Selenium operations.
import org.testng.annotations.Test;
public class LoginTest {
@Test
public void loginTest() {
LoginKeywords keywords =
new LoginKeywords();
keywords.openBrowser();
keywords.openUrl(
"https://example.com/login"
);
keywords.enterText(
"username",
"admin"
);
keywords.enterText(
"password",
"Admin123"
);
keywords.click("login");
keywords.closeBrowser();
}
}
15. Keyword-Driven Framework with Excel
Excel can be used to maintain keyword-driven test cases in a structured format.
| TestCase | Keyword | Object | Value |
| TC01 | OpenBrowser | - | Chrome |
| TC01 | OpenURL | - | https://example.com/login |
| TC01 | EnterText | username | admin |
| TC01 | EnterText | password | Admin123 |
| TC01 | Click | login | - |
| TC01 | VerifyText | message | Welcome |
| TC01 | CloseBrowser | - | - |
The framework reads each row and passes the information to the keyword engine.
16. Apache POI for Excel Keyword Data
Apache POI can be used in Java projects to read Excel files.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.4.1</version>
</dependency>
The dependency version should be aligned with the project's Java and dependency-management requirements.
17. Reading Keyword Data from Excel
import org.apache.poi.ss.usermodel.*;
import java.io.FileInputStream;
public class ExcelReader {
public static Object[][] readData(String filePath,
String sheetName)
throws Exception {
FileInputStream file =
new FileInputStream(filePath);
Workbook workbook =
WorkbookFactory.create(file);
Sheet sheet =
workbook.getSheet(sheetName);
int rows =
sheet.getPhysicalNumberOfRows();
int columns =
sheet.getRow(0)
.getPhysicalNumberOfCells();
Object[][] data =
new Object[rows - 1][columns];
for (int i = 1; i < rows; i++) {
for (int j = 0; j < columns; j++) {
data[i - 1][j] =
sheet.getRow(i)
.getCell(j)
.toString();
}
}
workbook.close();
file.close();
return data;
}
}
18. Excel-Based Keyword Execution Flow
Excel File
|
v
Read Test Case
|
v
Read Keyword
|
v
Read Object
|
v
Read Value
|
v
Keyword Engine
|
v
Keyword Implementation
|
v
Selenium WebDriver
|
v
Web Application
|
v
Execution Result
19. Object Repository
An Object Repository stores locators or element information separately from test steps.
username = id:username
password = id:password
loginButton = id:login
dashboardMessage = css:.welcome-message
Instead of putting locator values directly into every test case, the framework can resolve an object name to the appropriate Selenium locator.
20. Object Repository with Java
import org.openqa.selenium.By;
public class ObjectRepository {
public static By username() {
return By.id("username");
}
public static By password() {
return By.id("password");
}
public static By loginButton() {
return By.id("login");
}
public static By dashboardMessage() {
return By.cssSelector(".welcome-message");
}
}
21. Keyword Engine Using switch
A simple keyword engine can use a switch statement to identify the required action.
public void executeKeyword(String keyword,
String locator,
String value) {
switch (keyword) {
case "Click":
driver.findElement(
By.id(locator)
).click();
break;
case "EnterText":
driver.findElement(
By.id(locator)
).sendKeys(value);
break;
case "ClearText":
driver.findElement(
By.id(locator)
).clear();
break;
default:
throw new IllegalArgumentException(
"Unknown keyword: " + keyword
);
}
}
22. Keyword Engine Using Method Mapping
For a larger framework, keyword execution can be organized through a method-mapping mechanism instead of maintaining a very large switch statement.
Keyword Method
--------------------------------
Click click()
EnterText enterText()
ClearText clearText()
VerifyText verifyText()
TakeScreenshot takeScreenshot()
CloseBrowser closeBrowser()
This approach allows the framework to centralize the relationship between a keyword and its implementation.
23. Verification Keywords
Automation should not only perform actions; it should also verify the expected application behavior.
Common verification keywords include:
- VerifyText
- VerifyTitle
- VerifyURL
- VerifyElementPresent
- VerifyElementVisible
- VerifyAttribute
- VerifyValue
- VerifySelectedOption
24. VerifyText Keyword Example
public void verifyText(By locator,
String expected) {
String actual =
driver.findElement(locator).getText();
Assert.assertEquals(
actual,
expected
);
}
25. Handling Dropdowns with Keywords
Dropdown operations can be represented using a reusable keyword.
Keyword: SelectDropdown
Object: country
Value: India
Implementation:
import org.openqa.selenium.support.ui.Select;
public void selectDropdown(By locator,
String value) {
Select select =
new Select(driver.findElement(locator));
select.selectByVisibleText(value);
}
26. Handling Waits with Keywords
Synchronization is important in Selenium because modern web applications may load elements dynamically.
A framework can provide keywords such as:
WaitForElement
WaitForClickable
WaitForVisible
WaitForText
WaitForPageLoad
Example:
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
wait.until(
ExpectedConditions.elementToBeClickable(
By.id("login")
)
);
27. Browser Keywords
Browser-related actions can be implemented as reusable keywords.
| Keyword | Purpose |
| OpenBrowser | Launch selected browser. |
| CloseBrowser | Close browser session. |
| RefreshPage | Refresh current page. |
| NavigateBack | Navigate to previous page. |
| NavigateForward | Navigate to next page. |
| OpenURL | Navigate to a URL. |
| MaximizeWindow | Maximize browser window. |
28. WebElement Keywords
| Keyword | Action |
| Click | Click an element. |
| DoubleClick | Double-click an element. |
| EnterText | Enter text. |
| ClearText | Clear text. |
| GetText | Read element text. |
| MouseHover | Move mouse over an element. |
| DragAndDrop | Perform drag-and-drop. |
| ScrollToElement | Scroll to an element. |
29. Alert Keywords
Selenium alerts can also be represented through keywords.
AcceptAlert
DismissAlert
GetAlertText
EnterAlertText
Example:
public void acceptAlert() {
driver.switchTo().alert().accept();
}
public void dismissAlert() {
driver.switchTo().alert().dismiss();
}
30. Frame Keywords
Applications containing iframes require the framework to switch into the correct frame before interacting with its elements.
SwitchToFrame
SwitchToDefaultContent
Example:
public void switchToFrame(By locator) {
driver.switchTo().frame(
driver.findElement(locator)
);
}
public void switchToDefaultContent() {
driver.switchTo().defaultContent();
}
31. Window and Tab Keywords
Multiple browser windows and tabs can be managed through reusable keywords.
GetWindowHandles
SwitchToWindow
CloseCurrentWindow
SwitchToParentWindow
This makes multi-window workflows easier to represent in external test cases.
32. Screenshot Keyword
A screenshot keyword can capture the current browser state.
public void takeScreenshot(String fileName)
throws IOException {
TakesScreenshot screenshot =
(TakesScreenshot) driver;
File source =
screenshot.getScreenshotAs(
OutputType.FILE
);
File destination =
new File(
"screenshots/" +
fileName +
".png"
);
Files.copy(
source.toPath(),
destination.toPath()
);
}
33. Keyword-Driven Framework with Page Object Model
Keyword-driven testing and Page Object Model can be combined. POM organizes page-specific elements and behavior, while the keyword layer represents reusable test actions.
Test Case
|
v
Keyword Engine
|
v
Keyword Library
|
v
Page Object
|
v
Selenium WebDriver
|
v
Web Application
This separation can make a larger framework easier to organize.
34. Login Page Using POM
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class LoginPage {
private WebDriver driver;
private By username =
By.id("username");
private By password =
By.id("password");
private By loginButton =
By.id("login");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public void enterUsername(String value) {
driver.findElement(username)
.sendKeys(value);
}
public void enterPassword(String value) {
driver.findElement(password)
.sendKeys(value);
}
public void clickLogin() {
driver.findElement(loginButton)
.click();
}
public void login(String user,
String pass) {
enterUsername(user);
enterPassword(pass);
clickLogin();
}
}
35. Keyword-Driven Framework with Data-Driven Testing
Keyword-driven and data-driven approaches can be combined.
The keyword determines what action should be performed, while the test data determines which value should be used.
Keyword Object Value
--------------------------------------
EnterText username admin
EnterText password Admin123
Click login
VerifyText message Welcome
This combination is useful when the same workflow needs to be executed with many different input values.
36. Keyword-Driven vs Data-Driven Framework
| Keyword-Driven | Data-Driven |
| Focuses on reusable actions. | Focuses on separating data from test logic. |
| Uses keywords. | Uses external or parameterized data. |
| Uses a keyword engine. | Uses a data reader or TestNG DataProvider. |
| Test steps can be externalized. | Test input can be externalized. |
| Can use Excel for keyword definitions. | Can use Excel for test data. |
| Can be combined with data-driven testing. | Can be combined with keyword-driven testing. |
37. Keyword-Driven vs Page Object Model
| Keyword-Driven Framework | Page Object Model |
| Focuses on reusable automation actions. | Focuses on page elements and page behavior. |
| Uses keywords. | Uses page classes. |
| May use a keyword engine. | Uses page methods. |
| Can represent workflows externally. | Usually organizes Selenium interactions in Java classes. |
| Can use POM internally. | Can be part of a keyword-driven architecture. |
38. Keyword-Driven vs Linear Framework
| Linear Framework | Keyword-Driven Framework |
| Steps are directly coded in scripts. | Steps can be represented using keywords. |
| Usually simple to create. | Requires keyword architecture. |
| Limited action reuse unless explicitly designed. | Reusable keywords are a core concept. |
| Suitable for small scripts. | Useful for structured and reusable automation suites. |
| Maintenance may become harder as duplication grows. | Common keyword changes can be centralized. |
39. Advantages of Keyword-Driven Framework
- Reusability: The same keyword can be used across many tests.
- Maintainability: Common automation logic can be maintained centrally.
- Reduced duplication: Repeated Selenium code can be minimized.
- Readable test cases: Actions such as Click and EnterText are easy to recognize.
- Separation of concerns: Test steps can be separated from automation implementation.
- Scalability: A well-designed framework can support large test suites.
- Flexibility: New keywords can be added as requirements grow.
- External test design: Test steps can be maintained in Excel or other structured sources.
- Framework integration: It can be combined with POM, data-driven testing, reporting and CI/CD.
40. Disadvantages of Keyword-Driven Framework
- Initial framework development requires more effort.
- Keyword engine design can add complexity.
- Too many keywords can make the framework difficult to understand.
- Keyword naming must remain consistent.
- Debugging can require tracing several framework layers.
- External Excel-based test cases may become difficult to maintain at very large scale.
- Poorly designed keywords may become tightly coupled to specific pages.
- Generic keywords may not always represent complex business workflows cleanly.
41. Keyword Naming Standards
Keyword names should be meaningful, consistent and action-oriented.
Good examples:
OpenBrowser
OpenURL
EnterUsername
EnterPassword
ClickLogin
VerifyDashboard
TakeScreenshot
CloseBrowser
Avoid unclear names:
Action1
Method2
Step3
TaskA
Clear naming makes test cases easier to read and debug.
42. Handling Unknown Keywords
A robust framework should detect unsupported keywords and generate a meaningful error.
default:
throw new IllegalArgumentException(
"Unsupported keyword: " + keyword
);
The error message can also include the test case ID and execution step.
43. Keyword Validation
Before executing a test, the framework can validate whether every keyword is supported.
Supported Keywords:
OpenBrowser
OpenURL
EnterText
Click
ClearText
VerifyText
VerifyTitle
Screenshot
CloseBrowser
If the test file contains an invalid keyword, the framework should report it before or during execution rather than silently skipping it.
44. Configuration Management
Browser, URL, environment and timeout settings should generally be maintained separately from test cases.
browser=chrome
url=https://example.com
environment=qa
timeout=10
This allows the same test cases to be executed against different environments without changing keyword definitions.
45. Keyword-Driven Framework Folder Structure
KeywordDrivenFramework
|
+-- src
| |
| +-- main
| | |
| | +-- java
| | |
| | +-- keywords
| | | +-- BrowserKeywords.java
| | | +-- WebElementKeywords.java
| | | +-- VerificationKeywords.java
| | |
| | +-- engine
| | | +-- KeywordEngine.java
| | |
| | +-- pages
| | | +-- LoginPage.java
| | |
| | +-- utilities
| | +-- ExcelUtils.java
| | +-- ConfigReader.java
| | +-- ScreenshotUtils.java
| |
| +-- test
| |
| +-- java
| | +-- tests
| | +-- LoginTest.java
| |
| +-- resources
| +-- KeywordTestCases.xlsx
| +-- config.properties
|
+-- pom.xml
+-- testng.xml
46. Utility Classes
Utility classes provide common functions that should not be duplicated inside keyword implementations.
- ExcelUtils
- CSVUtils
- JSONUtils
- ConfigReader
- ScreenshotUtils
- WaitUtils
- BrowserUtils
- ReportUtils
- FileUtils
47. Assertions in Keyword-Driven Framework
Reusable assertion keywords allow the framework to validate application behavior consistently.
VerifyText
VerifyTitle
VerifyURL
VerifyElementPresent
VerifyElementVisible
VerifyAttribute
VerifyValue
For example:
public void verifyTitle(String expectedTitle) {
String actualTitle =
driver.getTitle();
Assert.assertEquals(
actualTitle,
expectedTitle
);
}
48. Reporting
Reporting is important because a keyword-driven framework may execute many individual steps. A useful report should identify the test case, keyword, object, result and failure details.
Test Case: LoginTest
Step 1: OpenBrowser -> PASS
Step 2: OpenURL -> PASS
Step 3: EnterText -> PASS
Step 4: EnterText -> PASS
Step 5: Click -> PASS
Step 6: VerifyText -> FAIL
Step 7: CloseBrowser -> PASS
Reporting tools such as ExtentReports or Allure can be integrated into Selenium automation projects.
49. Logging
Logging records the execution sequence and helps identify where failures occur.
INFO - Executing keyword: OpenBrowser
INFO - Browser: Chrome
INFO - Executing keyword: OpenURL
INFO - URL: https://example.com
INFO - Executing keyword: EnterText
INFO - Object: username
INFO - Executing keyword: Click
INFO - Object: login
Log messages should avoid exposing passwords, access tokens or other sensitive information.
50. Keyword-Driven Framework with Maven
Maven can manage project dependencies, compilation and automated test execution.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
</plugin>
</plugins>
</build>
The appropriate Maven plugin versions should be selected based on the project's Java and dependency requirements.
51. Keyword-Driven Framework with TestNG
TestNG can manage setup, test execution, assertions and teardown while the keyword engine controls Selenium operations.
@BeforeMethod
public void setUp() {
openBrowser();
}
@Test
public void loginTest() {
executeKeyword("OpenURL");
executeKeyword("EnterText");
executeKeyword("Click");
executeKeyword("VerifyText");
}
@AfterMethod
public void tearDown() {
closeBrowser();
}
52. Parallel Execution
Keyword-driven tests can be executed in parallel when WebDriver instances and test state are isolated correctly.
Test Case 1
|
+---- Thread 1 -> Browser 1
Test Case 2
|
+---- Thread 2 -> Browser 2
Test Case 3
|
+---- Thread 3 -> Browser 3
Sharing a single mutable WebDriver instance across parallel tests can cause test interference and should generally be avoided.
53. Cross-Browser Testing
The same keyword-driven test flow can be executed against multiple browsers.
Keyword Test
|
+---- Chrome
|
+---- Firefox
|
+---- Edge
|
v
Compare Results
Browser selection should preferably come from configuration instead of being hard-coded inside individual keywords.
54. Selenium Grid Integration
Selenium Grid can be used when keyword-driven tests need to run remotely or across multiple browser environments.
Keyword Test
|
v
Selenium Grid
|
+---- Chrome
+---- Firefox
+---- Edge
|
v
Execution Results
This allows a common keyword-driven test flow to be executed across different browser configurations.
55. CI/CD Integration
A keyword-driven Selenium framework can be integrated into CI/CD pipelines.
Developer Push
|
v
Git
|
v
Jenkins
|
v
Maven Test Execution
|
v
Keyword Engine
|
v
Selenium Tests
|
v
Reports
|
v
Build Result
JustAcademy's Selenium curriculum includes CI/CD concepts such as Jenkins integration, Git/version control and running automated tests in pipelines. :contentReference[oaicite:1]{index=1}
56. Security and Sensitive Test Data
Passwords, API tokens and other sensitive values should not be unnecessarily exposed in keyword files, source code, reports or logs.
- Use dedicated test accounts.
- Do not hard-code production credentials.
- Use environment variables or an approved secret-management solution.
- Mask passwords in reports and logs.
- Do not commit secrets to source-control repositories.
- Restrict access to sensitive test-data files.
57. Practical Project: Keyword-Driven Login Framework
Objective: Build a Selenium login automation framework where test cases are represented using keywords.
Test Case
| Step | Keyword | Object | Value |
| 1 | OpenBrowser | - | Chrome |
| 2 | OpenURL | - | Application URL |
| 3 | EnterText | username | admin |
| 4 | EnterText | password | Admin123 |
| 5 | Click | loginButton | - |
| 6 | VerifyText | dashboard | Welcome |
| 7 | Screenshot | - | login-success |
| 8 | CloseBrowser | - | - |
58. Practical Project: E-Commerce Automation
Project Objective: Automate an e-commerce application using reusable keywords.
Features
- Launch application.
- Login.
- Search product.
- Apply filters.
- Select product.
- Add product to cart.
- Validate cart.
- Proceed to checkout.
- Enter customer information.
- Place order.
- Verify order.
- Logout.
Keyword Flow
OpenBrowser
OpenURL
EnterText
Click
SearchProduct
VerifyProduct
ClickAddToCart
VerifyCart
ClickCheckout
EnterText
ClickPlaceOrder
VerifyOrder
Logout
CloseBrowser
59. Practical Project: Registration Testing
A registration workflow can also use reusable keywords.
OpenBrowser
OpenURL
Click
EnterText
EnterText
EnterText
SelectDropdown
Click
VerifyText
Screenshot
CloseBrowser
The same keyword library can be reused for different registration scenarios and data sets.
60. Practical Project: Search Testing
OpenBrowser
OpenURL
EnterText
Click
WaitForElement
VerifyText
Screenshot
CloseBrowser
The workflow can be executed with different search terms without rewriting the underlying Selenium methods.
61. Advantages of External Keyword Test Cases
- Test steps can be maintained in a structured format.
- Test cases can be reviewed separately from implementation code.
- Common keywords can be reused.
- Execution logic remains centralized.
- Test data can be maintained separately.
- Common action changes can be implemented in one location.
- Large test suites can be organized using test case IDs.
62. Common Mistakes
Mistake 1: Creating Too Many Keywords
Creating a separate keyword for every tiny operation can make the framework unnecessarily complex.
Mistake 2: Poor Keyword Names
Names such as Action1 or Step2 provide little information about the operation.
Mistake 3: Duplicating Keywords
Multiple keywords performing the same operation can increase maintenance effort.
Mistake 4: Hard-Coding Locators Everywhere
Locators should be organized through page objects or an object repository.
Mistake 5: Ignoring Assertions
Executing actions without validating the result does not provide sufficient evidence that the application behaved correctly.
Mistake 6: Poor Error Handling
Unknown keywords, missing objects and invalid values should generate meaningful failures.
Mistake 7: Exposing Sensitive Data
Passwords and tokens should not appear in logs or reports in plain text.
63. Best Practices
- Use clear and consistent keyword names.
- Keep generic keywords reusable.
- Maintain a centralized keyword library.
- Separate test cases from keyword implementation.
- Keep locators organized.
- Separate test data from framework logic.
- Use configuration files for environment settings.
- Use reusable utility classes.
- Implement logging.
- Generate detailed reports.
- Capture screenshots for important failures.
- Validate unsupported keywords.
- Use meaningful error messages.
- Protect credentials and secrets.
- Design WebDriver management carefully for parallel execution.
- Keep the framework modular.
- Remove obsolete or duplicate keywords periodically.
- Combine keyword-driven design with POM where appropriate.
64. Keyword-Driven Framework and Hybrid Framework
Keyword-driven design is often one component of a broader hybrid Selenium framework.
Hybrid Framework
|
+-- Keyword-Driven
|
+-- Data-Driven
|
+-- Page Object Model
|
+-- TestNG
|
+-- Maven
|
+-- Utilities
|
+-- Configuration
|
+-- Reporting
|
+-- Logging
|
+-- Git
|
+-- Jenkins
|
+-- Selenium Grid
A hybrid architecture allows each technique to handle a specific framework responsibility.
65. Real-World Keyword-Driven Architecture
AUTOMATION FRAMEWORK
|
+---------------------+---------------------+
| | |
v v v
Test Cases Test Data Configuration
| | |
v v v
Keyword Definitions Excel/CSV/JSON Properties
| |
+----------+----------+
|
v
Keyword Engine
|
v
Keyword Library
|
v
Page Objects
|
v
Selenium WebDriver
|
v
Web Application
|
+--------+--------+
| |
v v
Assertions Screenshots
| |
+--------+--------+
|
v
Reports
|
v
CI/CD
66. When Should You Use a Keyword-Driven Framework?
A keyword-driven approach can be useful when:
- The application contains many repeated actions.
- Multiple test cases share common workflows.
- The team wants reusable automation operations.
- Test steps need to be represented separately from Selenium implementation.
- The automation suite is large enough to benefit from structured abstraction.
- Test cases may be maintained in external structured files.
- The framework needs to combine reusable actions with external test data.
67. When Is It Less Suitable?
A full keyword-driven framework may introduce unnecessary complexity when:
- The project contains only a few simple test cases.
- The automation suite is small and short-lived.
- Most test actions are unique and cannot be reasonably generalized.
- The cost of maintaining a keyword engine is greater than the benefit of reusable keywords.
- The team does not need externalized or reusable test-step definitions.
68. Technology Stack
| Technology | Purpose |
| Java | Programming language for framework development. |
| Selenium WebDriver | Browser automation. |
| TestNG | Test execution and assertions. |
| Maven | Build and dependency management. |
| Apache POI | Excel file processing. |
| Git | Version control. |
| Jenkins | CI/CD automation. |
| ExtentReports / Allure | Reporting. |
| Log4j | Logging. |
| Selenium Grid | Remote and parallel browser execution. |
69. Interview Question: What Is a Keyword-Driven Framework?
Answer: A Keyword-Driven Framework is a Selenium automation framework in which test actions are represented using predefined keywords. Each keyword is mapped to a reusable automation method that performs an operation such as opening a browser, entering text, clicking an element or verifying application behavior.
70. Interview Question: What Is a Keyword?
Answer: A keyword is a predefined name representing an automation operation. Examples include OpenBrowser, OpenURL, EnterText, Click, VerifyText and CloseBrowser.
71. Interview Question: What Is a Keyword Engine?
Answer: A keyword engine reads test steps, identifies the keyword, retrieves the required object and value information, and invokes the corresponding automation method.
72. Interview Question: What Is a Keyword Repository?
Answer: A keyword repository is a collection of supported keywords and their corresponding implementations. It defines the actions that the framework can execute.
73. Interview Question: Can Keyword-Driven Framework Use Excel?
Answer: Yes. Excel can store test case IDs, keywords, objects and values. Apache POI can be used in Java to read the Excel data.
74. Interview Question: Can Keyword-Driven Framework Be Combined with POM?
Answer: Yes. Page Object Model can manage page-specific locators and operations, while the keyword layer can represent reusable actions or orchestrate workflows.
75. Interview Question: What Is the Difference Between Keyword-Driven and Data-Driven Framework?
Answer: Keyword-driven frameworks focus primarily on separating automation actions into reusable keywords, while data-driven frameworks focus primarily on separating input data from test logic. Both techniques can be combined in one framework.
76. Interview Question: What Are the Advantages of Keyword-Driven Framework?
- Reusable automation actions.
- Reduced code duplication.
- Separation of test steps and implementation.
- Centralized keyword implementation.
- Readable test cases.
- Structured automation architecture.
- Easy integration with data-driven testing and POM.
77. Interview Question: What Are the Disadvantages?
- Higher initial development effort.
- Keyword engine adds complexity.
- Large keyword libraries can become difficult to manage.
- Debugging can require tracing several framework layers.
- Poor keyword design can reduce maintainability.
78. Interview Question: How Do You Handle an Invalid Keyword?
Answer: The keyword engine should validate the keyword and generate a clear exception or test failure if it is unsupported. The error should ideally identify the keyword, test case and execution step.
79. Interview Question: How Can Keywords Be Made Reusable?
Answer: Keywords can be made reusable by creating generic operations such as Click, EnterText, VerifyText and SelectDropdown, separating locators from test data, avoiding unnecessary page-specific hard-coding, and maintaining common operations in reusable libraries.
80. Quick Comparison of Automation Frameworks
| Framework | Main Focus |
| Linear | Sequential automation scripts. |
| Modular | Reusable modules. |
| Library-Based | Reusable function libraries. |
| Data-Driven | Separating test data from test logic. |
| Keyword-Driven | Separating automation actions into keywords. |
| POM | Organizing page elements and page behavior. |
| BDD | Behavior-oriented scenario representation. |
| Hybrid | Combining multiple framework techniques. |
81. Keyword-Driven Framework Checklist
- Are keywords clearly named?
- Does every keyword have a valid implementation?
- Are test cases separated from automation implementation?
- Are locators managed systematically?
- Is test data separated from framework logic?
- Are assertions included?
- Are invalid keywords handled?
- Is logging implemented?
- Are screenshots captured for important failures?
- Are reports generated?
- Is WebDriver managed safely?
- Can the framework support parallel execution when required?
- Are sensitive credentials protected?
- Can the framework run through Maven?
- Can the framework be integrated with CI/CD?
82. Practical Assignment
Create a complete Keyword-Driven Selenium Framework for a login application.
Requirements
- Create a Maven Selenium project.
- Configure Selenium WebDriver.
- Configure TestNG.
- Create a keyword library.
- Create browser keywords.
- Create WebElement keywords.
- Create verification keywords.
- Create an object repository.
- Create an Excel keyword test sheet.
- Read Excel using Apache POI.
- Create a keyword execution engine.
- Execute login scenarios.
- Add assertions.
- Add screenshots.
- Add logging.
- Generate execution reports.
- Execute tests using Maven.
83. Advanced Practical Project
Project: Keyword-Driven E-Commerce Automation Framework
Modules to Automate
- Application launch
- User login
- Product search
- Product filtering
- Product selection
- Add to cart
- Cart validation
- Checkout
- Address entry
- Order placement
- Order verification
- Logout
Framework Flow
Excel Test Case
|
v
Keyword Engine
|
v
Keyword Library
|
v
Page Objects
|
v
Selenium WebDriver
|
v
E-Commerce Application
|
v
Assertions
|
v
Reports
84. Real-World Execution Flow
START
|
v
Read Configuration
|
v
Load Test Case
|
v
Read Keyword
|
v
Validate Keyword
|
+-----+-----+
| |
Valid Invalid
| |
v v
Read Object Report Error
|
v
Read Value
|
v
Execute Keyword
|
v
Selenium WebDriver
|
v
Validate Result
|
+----+----+
| |
PASS FAIL
| |
v v
Report Screenshot
| |
+----+----+
|
v
Next Keyword
|
v
More Steps?
/ \
Yes No
| |
+--------->v
END
85. Best Practices Summary
| Area | Best Practice |
| Keyword Naming | Use clear, consistent, action-oriented names. |
| Reusability | Create generic keywords where practical. |
| Object Management | Keep locators organized. |
| Test Data | Keep test data separate from implementation. |
| Assertions | Validate expected application behavior. |
| Error Handling | Report unsupported keywords clearly. |
| Logging | Record keyword execution without exposing secrets. |
| Reporting | Identify failed tests and failed steps. |
| Security | Protect passwords, tokens and sensitive data. |
| Scalability | Keep the framework modular and avoid unnecessary duplication. |
| CI/CD | Design the framework for automated Maven/Jenkins execution. |
86. Course Resources
Learn Selenium WebDriver, Java automation, TestNG, Page Object Model, data-driven testing, keyword-driven framework development, hybrid framework design, reporting, debugging, Selenium Grid and CI/CD through the following resource:
Selenium Training
For course demo registration:
Register for Course Demo
87. Final Summary
A Keyword-Driven Framework is a Selenium automation framework in which test actions are represented through reusable keywords. The keyword engine reads these actions, identifies the corresponding implementation, retrieves required objects and values, and executes the Selenium operation.
A professional keyword-driven framework can be combined with Page Object Model, Data-Driven Testing, TestNG, Maven, Apache POI, configuration management, logging, reporting, Git, Jenkins, Selenium Grid and CI/CD. This allows teams to build structured and reusable automation solutions.
88. One-Line Revision
Keyword-Driven Framework = Test Steps represented as reusable Keywords + Keyword Engine + Keyword Library + Selenium WebDriver + Test Data + Object Repository + Reporting.